<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>

<script>

    var attr=[[6671],[6673,6674],[6678,6677]];
    var attr_ar=[6671,6673,6674,6678,6677];
    var sku=[["6671","6673","6677"],["6671","6674","6677"]];
    var sku_ar=[1,2,4,5,6];
    var key=4;
    var key_ar=[2,4];
    function sku_select(attr,attr_ar,sku,sku_ar,key,key_ar) {
            var kexuan_ar=[];
            var jinxuan_ar=[];
            var jinxuan_ar=attr_ar.filter(function(v){ return sku_ar.indexOf(v) == -1 })
            var sku_length=sku.length;

            var p=0;
            for(i=0;i<sku_length;i++){
                var jiao_ar=sku[i].filter(function(v){ return key_ar.indexOf(v) == -1 })
                if(jiao_ar.length==key_ar.length){
                    p=1;
                }
            }
            if(p==0){
                key_ar=[key];
            }


            for(i=0;i<sku_length;i++){
                var jiao_ar=sku[i].filter(function(v){ return key_ar.indexOf(v) == -1 })
                if(jiao_ar.length==key_ar.length){
                     kexuan_ar=kexuan_ar.concat(sku[i].filter(function(v){ return !(kexuan_ar.indexOf(v) > -1)}));
                }
            }

            var attr_length=attr.length;
            for(i=0;i<attr_length;i++){
                var jiao_ar=attr[i].filter(function(v){ return key_ar.indexOf(v) == -1 })
                if(jiao_ar.length>0){
                    kexuan_ar=kexuan_ar.concat(attr[i].filter(function(v){ return !(kexuan_ar.indexOf(v) > -1)}));
                }
            }

            var jinxuan1_ar=attr_ar.filter(function(v){ return kexuan_ar.indexOf(v) == -1 });

            jinxuan_ar=jinxuan_ar.concat(jinxuan1_ar.filter(function(v){ return !(jinxuan_ar.indexOf(v) > -1)}));

            kexuan_ar=kexuan_ar.filter(function(v){ return jinxuan_ar.indexOf(v) == -1 })
            kexuan_ar=kexuan_ar.filter(function(v){ return key_ar.indexOf(v) == -1 })

            return   [key_ar,jinxuan_ar,kexuan_ar];
    }
    var aa = sku_select(attr,attr_ar,sku,sku_ar,key,key_ar);
    console.log(aa);

    var a = [1,2,3,4,5]
    var b = [2,4,6,8,10]

    //交集
    var c = a.filter(function(v){ return b.indexOf(v) > -1 })

    //差集
    var d = a.filter(function(v){ return b.indexOf(v) == -1 })

    //补集
    var e = a.filter(function(v){ return !(b.indexOf(v) > -1) })
        .concat(b.filter(function(v){ return !(a.indexOf(v) > -1)}))

    //并集
    var f = a.concat(b.filter(function(v){ return !(a.indexOf(v) > -1)}));



</script>